package cn.earl.springboot.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.Pattern;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.NotBlank;

import com.alibaba.fastjson.annotation.JSONField;

@Entity
@Table(name = "tb_user")
public class User {

	@Id
	@GeneratedValue // 主键生成策略，默认AUTO
	private int id;

	@NotBlank
	@Column(name = "username", unique = true)
	private String username;

	@NotBlank
	private String password;

	@Column(unique = true)
	@Pattern(regexp = "^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\\d{8}$", message = "手机号码格式不正确")
	private String phone_number;

	@JSONField(format = Global.DATE_FORMAT)
	private Date regist_date;

	// 信用
	private double credit;
	// 验证码
	private String code;
	// 头像
	private String portrait;
	// 每天的可撤销次数
	private int revocation;
	// 确认密码
	private int confirm;
	// 激活状态
	@Column(columnDefinition = "bool default false")
	private boolean status;
	// 所有需求
	// mappedBy指定维护外键关系的那一方，相当于hibernate的inverse=true
	@OneToMany(mappedBy = "user", targetEntity = Demand.class)
	@LazyCollection(LazyCollectionOption.EXTRA)
	private List<Demand> demands;

	public List<Demand> getDemands() {
		return demands;
	}

	public void setDemands(List<Demand> demands) {
		this.demands = demands;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getPhone_number() {
		return phone_number;
	}

	public void setPhone_number(String phone_number) {
		this.phone_number = phone_number;
	}

	public Date getRegist_date() {
		return regist_date;
	}

	public void setRegist_date(Date regist_date) {
		this.regist_date = regist_date;
	}

	public double getCredit() {
		return credit;
	}

	public void setCredit(double credit) {
		this.credit = credit;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getPortrait() {
		return portrait;
	}

	public void setPortrait(String portrait) {
		this.portrait = portrait;
	}

	public int getRevocation() {
		return revocation;
	}

	public void setRevocation(int revocation) {
		this.revocation = revocation;
	}

	public int getConfirm() {
		return confirm;
	}

	public void setConfirm(int confirm) {
		this.confirm = confirm;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

}
